package com.sam.im.sms.reciever;

import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.sam.im.sms.index.activitys.ThreadDetailActivity;

/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/6/4.
 */
public class NotificationBroadcastReceiver extends BroadcastReceiver {
    //type是为了Notification更新信息
    public static final String TYPE = "type";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        int type = intent.getIntExtra(TYPE, -1);
        String address = intent.getStringExtra("phone");
        if (type != -1) {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(type);
        }
        if (action.equals("notification_clicked")) {
            Intent i = new Intent(context, ThreadDetailActivity.class);
            i.putExtra("phone", address);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            context.startActivity(i);
        }
    }
}
